package com.leanyuan.check.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.leanyuan.check.domain.Inspection;
import com.leanyuan.check.dto.Inspectiondto;
import com.leanyuan.check.service.InspectionService_C;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/leanyuan/Inspection")
public class InspectionController {

    @Autowired
    InspectionService_C inspectionServiceC;

    //分页条件查询
    @RequestMapping("FindAllInspection")
    public Page<Inspectiondto> FindAllInspection(Integer pagesize, Integer pageno, Model model){
        Page<Inspectiondto> list= inspectionServiceC.InspectiondtolistPage(pageno,pagesize);
        model.addAttribute("Inspectionlist",list);
        return list;
    }

    @RequestMapping("FindAllInspection2")
    public List<Inspection> FindAllInspection2(Model model){
        List<Inspection> list= inspectionServiceC.selectInspection();
        model.addAttribute("Inspectionlist",list);
        return list;
    }

    //分页条件查询
    @RequestMapping("FindAllInspection1")
    public Page<Inspectiondto> FindAllInspection1(Integer id,String type, String inspection, Integer pagesize, Integer pageno, Model model){
        System.out.println(id+type+inspection);
        Page<Inspectiondto> list= inspectionServiceC.InspectiondtolistPage1(pageno,pagesize,id,type,inspection);
        model.addAttribute("Inspectionlist",list);
        return list;
    }


    //添加任务
    @RequestMapping("SaveInspection")
    public String SaveInspection(@RequestBody Inspection inspection){
        System.out.println(inspection);

        boolean flag= inspectionServiceC.save(inspection);
        if(flag)return "添加成功";
        return "添加失败";
    }
    //修改任务
    @RequestMapping("UpdateInspection")
    public String UpdateInspection(@RequestBody Inspection inspection){
        System.out.println(inspection);
        QueryWrapper<Inspection> queryWrapper=new QueryWrapper<Inspection>();
        queryWrapper.eq("Inspection_D",inspection.getInspectionD());
        boolean flag= inspectionServiceC.update(inspection,queryWrapper);
        if(flag)return "修改成功";
        return "修改失败";
    }
    //删除任务
    @RequestMapping("DeleteInspection")
    public String DeleteInspection(Integer id){
        boolean flag= inspectionServiceC.removeById(id);
        if(flag)return "删除成功";
        return "删除失败";
    }
}
